from django.shortcuts import render, redirect
from user_operations.forms import CommentvaliForm
from django.http import Http404,HttpResponse
# Create your views here.
def comment(request):
    """
    接受评论，并入库
    :param request:
    :return:
    """

    comment_data = dict()
    url_source = request.META.get("HTTP_REFERER")
    if not request.user.id:
        return redirect(url_source)
    commodity = request.POST.get("food",None)
    content = request.POST.get("content",None)
    comment_data["user"] = request.user.id
    comment_data["content"] = content
    comment_data["commodity"] = commodity
    data = CommentvaliForm(comment_data)


    if not data.is_valid():

        return redirect(url_source)

    data.save()

    return redirect(url_source)
